gendir = gen
srcdir = src
extdir = ext
closuredir = $(extdir)/closure
jsdocdir = $(extdir)/jsdoc-toolkit
distdir = dist
docdir = $(distdir)/doc
releasedir = js-binary-reader-$(VERSION)

VERSION = 0.1
RELEASEFILE = $(releasedir).tar.gz

JAVA = java
CLOSURE = $(JAVA) -jar $(closuredir)/compiler.jar --warning_level VERBOSE
JSDOC = $(JAVA) -jar $(jsdocdir)/jsrun.jar $(jsdocdir)/app/run.js \
	-t=$(jsdocdir)/templates/jsdoc

dist: closure doc

JS = $(srcdir)/binary-reader.js
EXTERNS = $(srcdir)/binary-reader.externs
MINFILE = $(distdir)/binary-reader.js

closure: $(MINFILE)

$(MINFILE): $(JS) $(EXTERNS)
	mkdir -p $(distdir)
	$(CLOSURE) --js_output_file $@ \
	 --compilation_level ADVANCED_OPTIMIZATIONS \
	$(shell for js in $(JS) ; do echo --js $$js ; done) \
	$(shell for ext in $(EXTERNS) ; do echo --externs $$ext ; done)

GEN = $(gendir)/binary-reader.tt $(gendir)/generate.pl

$(srcdir)/binary-reader.js: $(GEN)
	$(gendir)/generate.pl

DOCDEP = $(docdir)/index.html

doc: $(DOCDEP)

$(DOCDEP): $(JS) $(EXTERNS)
	mkdir -p $(docdir)
	$(JSDOC) -a -d=$(docdir) $(JS) $(EXTERNS)

release: $(RELEASEFILE)

$(RELEASEFILE): dist
	mkdir -p $(releasedir)
	cp -r $(distdir)/* $(releasedir)
	tar -caf $@ $(releasedir)

clean:
	rm -rf $(distdir) $(releasedir)
	rm -f $(srcdir)/binary-reader.js $(RELEASEFILE)
